import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
// const EasyWebpack = require('easywebpack-vue');
// const easywebpack = require('easywebpack');
// const webpackConfig = easywebpack.getWebpackConfig({
//   egg: true,
//   env: 'prod',
//   target: 'web'
// });

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1564227102438_5820';

  config.proxy = true;

  config.cluster = {
    listen: {
      port: 3000,
      hostname: '0.0.0.0'
      // path: '/var/run/egg.sock',
    }
  };

  config.logger = {
    disableConsoleAfterReady: false,
  };


  exports.development = {
    watchDirs: [], // 指定监视的目录（包括子目录），当目录下的文件变化的时候自动重载应用，路径从项目根目录开始写
    ignoreDirs: ['app/web', 'public', 'config/manifest.json'] // 指定过滤的目录（包括子目录）
  };

  // add your egg config in here
  config.middleware = [ 'exceptionHandler' ];

  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.html': 'nunjucks',
      '.njk': 'nunjucks'
    },
  };

  const onerror = {
    html(err, ctx) {
      // html hander
      ctx.body = '<h3>error' + err + '</h3>';
      ctx.status = 500;
    },
    json(err, ctx) {
      // json hander
      ctx.body = { message: 'error--' + err };
      ctx.status = 500;
    }
  };


  const webpack = {
    port: 9000,
    webpackConfigList: [require('../build/webpack.dev.config.js')],
    proxy: {
      host: 'http://127.0.0.1:9000',
      match: /^\/public\/static\//,
    },
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    // ...bizConfig,
    webpack,
    onerror
  };
};
